class NodeMap:
    def __init__(self):
        self.__keyList = []
        self.__kvMap= {}

    def insert(self, key, value):
        assert(len(self.__keyList) == len(self.__kvMap))

        usedIndex = len(self.__keyList) - 1
        self.__keyList.append(key)
        while usedIndex >= 0:
            if key < self.__keyList[usedIndex]:
                self.__keyList[usedIndex+1] = self.__keyList[usedIndex]
            else: # key >= keyList[i]
                self.__keyList[usedIndex+1] = key
                break
            usedIndex -= 1
        if usedIndex < 0:
            self.__keyList[0] = key

        self.__kvMap[key] = value

    def __str__(self):
        string = ",\n".join(str(i) for i in self.__keyList)
        value = ""
        for k in self.__keyList:
            value += "%s,\n" % self.__kvMap[k]
        return string #+ "\n\n v:[" + value + "]"


    def remove(self, key):
        index = self.find(key)
        if -1 != index:
            del self.__keyList[index]
            del self.__kvMap[key]
            return 0
        else:
            return -1
        #end if

    def find(self, key):
        try:
            return self.__keyList.index(key)
        except ValueError:
            return -1

    def size(self):
        return len(self.__keyList)

    def first(self):
        if self.size() > 0:
            return self.__kvMap[self.__keyList[0]], self.__keyList[0]
        return None

    def firstbigThan(self, key):
        if self.size() == 0:
            return None
        used = len(self.__keyList)
        i = 0 
        while i < used:
            if key <= self.__keyList[i]:
                return self.__kvMap[self.__keyList[i]],  self.__keyList[i]
            i += 1 
        if i >= used:
            return self.first()
        return None, None


import unittest
class TestNodeMap(unittest.TestCase):
    def test(self):
        nm = NodeMap() 
        self.assertEqual(nm.size(), 0)
        nm.insert(2, "string2")
        self.assertEqual(nm.size(), 1)
        nm.insert(1, "string1")
        self.assertEqual(nm.size(), 2)
        nm.insert(3, "string3")
        self.assertEqual(nm.size(), 3)

        print(str(nm))

        self.assertEqual(-1, nm.find(4))
        self.assertEqual(0, nm.find(1))
        self.assertEqual(1, nm.find(2))
        self.assertEqual(2, nm.find(3))


        self.assertEqual(-1, nm.remove(4))
        self.assertEqual(nm.size(), 3)

        self.assertEqual(0, nm.remove(2))
        self.assertEqual(nm.size(), 2)
        self.assertEqual(-1, nm.find(2))
        self.assertEqual(0, nm.find(1))
        self.assertEqual(1, nm.find(3))


        self.assertEqual(0, nm.remove(1))
        self.assertEqual(-1, nm.find(1))
        self.assertEqual(nm.size(), 1)
        self.assertEqual(0, nm.find(3))

        self.assertEqual(0, nm.remove(3))
        self.assertEqual(-1, nm.find(3))
        self.assertEqual(nm.size(), 0)

if __name__ == "__main__":
    suite = unittest.TestSuite([
        unittest.TestLoader().loadTestsFromTestCase(TestNodeMap),
        ])
    unittest.TextTestRunner(verbosity=2).run(suite)
